/********************************************************************
*
* FILENAME:     mspdef.h
*
* DESCRIPTION:  Header file for Media Stream Protocol Processing API
*
* FUNCTIONS:
*
* CALLING FORMAT AND ARGUMENT DESCRIPTIONS:
*
* OTHER DATA ACCESS, OTHER ACTIONS:
*
*
* COMMENTS:
*       This is the header file for the MSPP API.
*
* Copyright 2001 by NMS Communications.  All rights reserved.
*
********************************************************************/
#include "ctadef.h"
#include "nmstypes.h"
#include "mspobj.h"
#include "mspinit.h"
#include "msptypes.h"

#ifndef MSPDEF_INCLUDED
#define MSPDEF_INCLUDED

#ifdef __cplusplus
extern "C" {
#endif

/*-----------------------------------------------------------------------------
  MSP Version Ids
    - These id's are used to identify the revision level of this service.

        major minor Description
        1     0     Fusion 4.0 Beta
        1     1     Fusion 4.0 GA
  ---------------------------------------------------------------------------*/
#define MSP_MAJORREV                        1
#define MSP_MINORREV                        1

/*-----------------------------------------------------------------------------
  MSP API Compatibility Level Id
    - This id is used to determine runtime compatibility between the
      installed MSP service and clients of the MSP service.
    - API compatibility level value is incremented when the associated
      source module changes in a non-backwards compatible way.
  ---------------------------------------------------------------------------*/
#define MSPAPI_COMPATLEVEL                  1


/***********************************************************************
            TYPEDEFS, CONSTANTS AND MACRO DEFINITIONS
************************************************************************/

typedef enum tag_MSP_CONNECTION_TYPE
{
    MSP_DUPLEX,                /* Full-duplex connection */
    MSP_SIMPLEX_ENCODE,        /* Simplex, Encode side connection */
    MSP_SIMPLEX_DECODE,        /* Simplex, Decode connection */
    MSP_SIMPLEX                /* Generic Simplex no coding */
} MSP_CONNECTION_TYPE;
#define MSP_NO_CONNECT 0       /* for Native Record non-connection */    

typedef DWORD MSPHD;

/***********************************************************************
        MSPP Event Definitions
************************************************************************/
#define MSPEVN_BASE                          0x001b2000    /* ((XXX_SVCID<<16)|(CTA_CODE_EVENT|0x00)) */

/* Endpoint done events */
#define MSPEVN_CREATE_ENDPOINT_DONE          0x001b2001
#define MSPEVN_DESTROY_ENDPOINT_DONE         0x001b2002
#define MSPEVN_ENABLE_ENDPOINT_DONE          0x001b2003
#define MSPEVN_DISABLE_ENDPOINT_DONE         0x001b2004

/* Channel done events */
#define MSPEVN_CREATE_CHANNEL_DONE           0x001b2005
#define MSPEVN_DESTROY_CHANNEL_DONE          0x001b2006
#define MSPEVN_ENABLE_CHANNEL_DONE           0x001b2007
#define MSPEVN_DISABLE_CHANNEL_DONE          0x001b2008
#define MSPEVN_CONNECT_DONE                  0x001b2009
#define MSPEVN_DISCONNECT_DONE               0x001b200a
#define MSPEVN_SENDCOMMAND_DONE              0x001b2100
#define MSPEVN_QUERY_DONE                    0x001b2200

/* add other channel events here */

/* Macros for checking event codes */
#define MSP_CODE_EVENT_MASK                 0xfffff000
#define MSP_IS_EVENT(event)                 (((event) & MSP_CODE_EVENT_MASK) == MSPEVN_BASE)
#define MSP_CMD_OR_QRY_DONE_EVENT_MASK      0xffffff00
#define MSP_IS_SENDCOMMAND_DONE(event)      (((event) & MSP_CMD_OR_QRY_DONE_EVENT_MASK) == MSPEVN_SENDCOMMAND_DONE)
#define MSP_IS_QUERY_DONE(event)            (((event) & MSP_CMD_OR_QRY_DONE_EVENT_MASK) == MSPEVN_QUERY_DONE)
#define MSP_IS_CMD_OR_QRY_DONE_EVENT(event) (MSP_IS_SENDCOMMAND_DONE(event)) || (MSP_IS_QUERY_DONE(event))

/* Unsolicited event identifiers Range: 0x001b2300 - 0x001b23ff */
/* Refer to mspunsol.h for identifiers and event buffer definitions */


/***********************************************************************
        MSPP Reason codes
************************************************************************/
#define MSPRSN_BASE                          0x001b1000    /* ((MSP_SVCID<<16)|(CTA_CODE_REASON|0x0)) */
#define MSPRSN_FAILED_TO_ALLOCATE            0x001b1001    /* Unable to allocate onboard resource */
#define MSPRSN_FAILED_TO_DEALLOCATE          0x001b1002    /* Unable to deallocate onboard resource */
#define MSPRSN_FAILED_TO_START               0x001b1003    /* Unable to start onboard resource */
#define MSPRSN_FAILED_TO_STOP                0x001b1004    /* Unable to stop onboard resource */
#define MSPRSN_FAILED_TO_INTRACONNECT        0x001b1005    /* Unable to connect filters within channel*/
#define MSPRSN_FAILED_TO_INTRADISCONNECT     0x001b1006    /* Unable to disconnect filters withing the channel */
#define MSPRSN_FAILED_TO_INTERCONNECT        0x001b1007    /* Unable to connect channel to endpont */
#define MSPRSN_FAILED_TO_INTERDISCONNECT     0x001b1008    /* Unable to disconnect channel from endpoint */


/***********************************************************************
            MSP SPECIFIC ERROR CODES
************************************************************************/
#define MSPERR_BASE                          0x001b0000  /* ((MSP_SVCID<<16)|(CTA_CODE_ERROR|0x0)) */
#define MSPERR_INVALID_CONNECTION            0x001b0001
#define MSPERR_INTERNAL_HANDLE               0x001b0002
#define MSPERR_CANNOT_OPEN_SERVICE_COMPONENT 0x001b0003  /* Cannot open a sub-component of the service */
#define MSPERR_INVALID_HANDLE                0x001b0004  /* Invalid endpoint or channel handle */
#define MSPERR_CHANNEL_NOT_DEFINED           0x001b0005  /* Channel name is not defined */
#define MSPERR_CHANNEL_NOT_CONNECTED         0x001b0006  /* Channel is not connected to any endpoints */
#define MSPERR_ENDPOINT_NOT_ALLOCATED        0x001b0007  /* Ep is defined, but not allocated yet on board */
#define MSPERR_DRIVER_COMMAND_FAILED         0x001b0008  /* SPI command failed */
#define MSPERR_UNKNOWN_FILTER_OBJECT         0x001b0009  /* The command specified a filter that is not in the channel */
#define MSPERR_SENDCOMMAND_FAILED            0x001b000a  /* the send command api call returned an errror */
#define MSPERR_SENDQUERY_FAILED              0x001b000b  /* the Query api call failed */
#define MSPERR_ENDPOINT_BUSY                 0x001b000c  /* Command arrived while servicing previous command*/
#define MSPERR_FILTER_BUSY                   0x001b000d  /* Command arrived while servicing previous command*/

#define MSPERR_ENDPOINT_IS_ENABLED           0x001b000e
#define MSPERR_ENDPOINT_IS_DISABLED          0x001b000f
#define MSPERR_CHANNEL_IS_ENABLED            0x001b0010
#define MSPERR_CHANNEL_IS_DISABLED           0x001b0011
#define MSPERR_NO_LICENSE_AVAILABLE          0x001b0012  /* License required but none is available */
#define MSPERR_LM_ERROR                      0x001b0013  /* License required but license manager is unavailable */


/***********************************************************************
        ENDPOINT STRUCTURES
************************************************************************/


typedef struct tag_MSP_ENDPOINT_PARMS
{
    DWORD   size;       // size of MSP_ENDPOINT_PARAMS)
    DWORD   eParmType;  // MSP_ENDPOINT_DS0, MSP_ENDPOINT_RTPFDX, etc

    union
    {
        DS0_ENDPOINT_PARMS          DS0;
        PKTMEDIA_ENDPOINT_PARMS     PktMedia;
        MONITOR_ENDPOINT_PARMS      Monitor;
        RTPRTCP_ENDPOINT_PARMS      RtpRtcp;
        UDP_ENDPOINT_PARMS          Udp;
        T38UDP_ENDPOINT_PARMS       T38Udp;
        TPKT_ENDPOINT_PARMS         Tpkt;
        MUX_ENDPOINT_PARMS          Mux;
        UNDEFINED_ENDPOINT_PARMS    Undefined;
        // Structure may be expanded to define new Endpoints
        RTPRTCP_V6_ENDPOINT_PARMS   RtpRtcpV6;
        UDP_V6_ENDPOINT_PARMS       UdpV6;
    } EP;

} MSP_ENDPOINT_PARAMETER;


typedef struct tag_MSP_ENDPOINT_ADDR
{
    DWORD   size;       // ENDPOINT_ADDR
    DWORD   nBoard;     // board number
    DWORD   eEpType;    // MSP_ENDPOINT_DS0, MSP_ENDPOINT_RTPFDX, etc

    union
    {
        DS0_ENDPOINT_ADDR           DS0;
        PKTMEDIA_ENDPOINT_ADDR      PktMedia;
        MONITOR_ENDPOINT_ADDR       Monitor;
        RTPRTCP_ENDPOINT_ADDR       RtpRtcp;
        UDP_ENDPOINT_ADDR           Udp;
        T38UDP_ENDPOINT_ADDR        T38Udp;
        MUX_ENDPOINT_ADDR           Mux;

        // New Endpoints to support IPv6
        RTPRTCP_V6_ENDPOINT_ADDR    RtpRtcpV6;
        UDP_V6_ENDPOINT_ADDR        UdpV6;

        // Structure may be expanded to define new Endpoints
    } EP;

} MSP_ENDPOINT_ADDR;


/***********************************************************************
        CHANNEL STRUCTURES
************************************************************************/

typedef enum msp_channel_type
{
    NOT_DEFINED,
    G711FullDuplex,
    G723FullDuplex,
    G726FullDuplex,
    G729FullDuplex,
    FaxRelayFullDuplex,
    G711EncodeSimplex,
    G711DecodeSimplex,
    G723EncodeSimplex,
    G723DecodeSimplex,
    G726EncodeSimplex,
    G726DecodeSimplex,
    G729EncodeSimplex,
    G729DecodeSimplex,
    G728FullDuplex,
    G728EncodeSimplex,
    G728DecodeSimplex,
    RTPSwitchingSimplex,
    RTPPassthruSimplex,
    AMRFullDuplex,
    AMREncodeSimplex,
    AMRDecodeSimplex,
    MGVideoChannel,
    MGAMRChannel,
    MGG711Channel,
    MGAMRBypassChannel,
    MGH263VideoChannel,
    DeprecatedChannelNumber_DoNotUse,
    MGG723BypassChannel,
    G711RecordChannel,
    G726RecordChannel,
    G729RecordChannel,
    G723RecordChannel,
    AMRRecordChannel,
    MGVideoChannelInSimplex,
    MGVideoChannelOutSimplex,
    MGAMRChannelEncodeSimplex,
    MGAMRChannelDecodeSimplex,
    MGAMRBypassChannelInSimplex,
    MGAMRBypassChannelOutSimplex,
    MGH263VideoChannelInSimplex,
    MGH263VideoChannelOutSimplex,
    MGG723BypassChannelInSimplex,
    MGG723BypassChannelOutSimplex,
    EVRCFullDuplex,
    EVRCEncodeSimplex,
    EVRCDecodeSimplex,
	ILBC20FullDuplex,
	ILBC20EncodeSimplex,
	ILBC20DecodeSimplex,
    ILBC30FullDuplex,
	ILBC30EncodeSimplex,
	ILBC30DecodeSimplex,
	GSMFRFullDuplex,
	GSMFREncodeSimplex,
	GSMFRDecodeSimplex,
    MGH264VideoChannel,
    MGH264VideoChannelInSimplex,
    MGH264VideoChannelOutSimplex
} MSP_CHANNEL_TYPE;

typedef struct tag_MSP_CHANNEL_PARMS
{

    DWORD               size;
    MSP_CHANNEL_TYPE    channelType;

    union
    {
        MSP_VOICE_CHANNEL_PARMS            VoiceParms;
        MSP_FAX_CHANNEL_PARMS              FaxParms;
        MSP_RTP_SWITCHING_CHANNEL_PARMS    RtpSwitchingParms;
        MSP_VIDEO_CHANNEL_PARMS            VideoParms;
        MSP_AUDIO_CHANNEL_PARMS            AudioParms;
        MSP_UNDEFINED_CHANNEL_PARMS        Undefined;
        // Structure may be expanded to define new Channel Types
    } ChannelParms;

} MSP_CHANNEL_PARAMETER;


typedef struct tag_MSP_CHANNEL_ADDR
{
    DWORD            size;
    DWORD            nBoard;        // Channel location (board number)
    MSP_CHANNEL_TYPE channelType;
    DWORD            FilterAttribs;  // Used to enable DSP Filter functions
} MSP_CHANNEL_ADDR;

#ifndef IPV6ADDR
typedef union {
        U8  byByte[16];
        U16 byWord[8];
        U32 byLong[4];
} IPV6Addr;
#define IPV6ADDR
#endif // IPv6ADDR

/***********************************************************************
        API FUNCTIONS
************************************************************************/

// Endpoint operations
DWORD NMSAPI mspCreateEndpoint (CTAHD ctahd,
                                MSP_ENDPOINT_ADDR* addr,
                                MSP_ENDPOINT_PARAMETER* parm,
                                MSPHD* ephd);

DWORD NMSAPI mspDestroyEndpoint( MSPHD ephd );


// Channel operations
DWORD NMSAPI mspCreateChannel (CTAHD ctahd,
                               MSP_CHANNEL_ADDR* addr,
                               MSP_CHANNEL_PARAMETER* parm,
                               MSPHD* chnhd );

DWORD NMSAPI mspDestroyChannel (MSPHD chnhd );

// Connect operations
DWORD NMSAPI mspConnect (MSPHD ephd1,
                         MSPHD chnhd,
                         MSPHD ephd2);

DWORD NMSAPI mspDisconnect (MSPHD ephd1,
                            MSPHD chnhd,
                            MSPHD ephd2);

// Enable and Disable operations
DWORD NMSAPI mspEnableEndpoint (MSPHD ephd );

DWORD NMSAPI mspDisableEndpoint (MSPHD ephd );

DWORD NMSAPI mspEnableChannel (MSPHD chnhd );

DWORD NMSAPI mspDisableChannel (MSPHD chnhd );


// Attribute and Command modification operations
DWORD NMSAPI mspSendCommand (MSPHD msphd,
                             DWORD command,
                             void* pBuffer,
                             DWORD size );
// Query Operation
DWORD NMSAPI mspSendQuery (MSPHD msphd,
                           DWORD query);

// Get Filter Handle (synchronous)
DWORD NMSAPI mspGetFilterHandle( MSPHD hMsp,      // channel or endpoint handle
                                 DWORD Filter,    // MSP_FILTER_xxx
                                 DWORD *pHandle); // returned handle

// Miscellaneous
DWORD NMSAPI mspReleaseBuffer (MSPHD msphd, void *buffer);

#ifdef __cplusplus
}
#endif

#endif //MSPDEF_INCLUDED

